#include <iostream>
#include <string>

using namespace std;

// function takes a char array as input.
// modifies it to remove duplicates and adds a 0 to mark the end
// of the unique chars in the array.
void removeDuplicate(char str[] ){
	
	int size = strlen(str);
	int i, j, 
		last = 1;// number of unique char in the array.

	if (size < 2)
		return;
	// start at 2nd char and go till the end of the array.
	for (i = 1; i < size; i++){
		// for every char in outer loop check if that char is already seen.
    // char in [0,tail) are all unique.
		for (j = 0; j < last; j++){
			if (str[i] == str[j])
				break;
		}
		 // if j reachs tail..we did not break, which implies this char at pos i
    // is not a duplicate. So we need to add it our "unique char list"
    // we add it to the end, that is at pos tail.
		if (last == j)
			str[last++] = str[i];// increment tail...[0,tail) is still "unique char list"
	}

	str[last] = '\0';

	
}

int removeDuplicateTest(){
	//char str[] = "thisisastringwithduplicate";//thisarngwduplce
	char str[] = "my name is chun li";
	removeDuplicate(str);
	cout <<str <<endl;

	cin.get();
	return 0;
}